<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<!-- 卷内件排序模态框（Modal） -->
<div class="modal fade" id="AdjustOrderModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document" style="width:60%;">
        <div class="modal-content" <%--style="height: 100%;"--%>>
            <div class="modal-header" <%--style="height: 5%;"--%>>
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">卷内件排序</h4>
                <span style="color: red;font-size: 12px">*请上下拖动完成后提交更改</span>
            </div>
            <div class="modal-body" style="padding-top:5px;height: 550px;">
                <table id="orItemListTable" md-grid-tile-header="true" class="orItemListTable" data-use-row-attr-func="true" data-reorderable-rows="true"></table>
            </div>
            <div class="modal-footer" style="height: 5%;">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" onclick="orStartAdjust()" class="btn btn-primary">提交更改</button>
            </div>
        </div>
    </div>
</div>

<!-- 分卷模态框（Modal） -->
<div class="modal fade" id="segmentVolumeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="height: 750px;width: 1000px">
        <div class="modal-content" style="height: 100%;">
            <div class="modal-header" style="height: 5%;">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="segmentVolumeTitle">分卷调整</h4>
            </div>
            <div class="modal-body" style="height: 80%;">
                <div style="height: 40px;width: 100%;float: right;">
                    <div class="top" style="height: 50px;float: right;">
                        <div class="form-inline" style="width: 400px">
                            <label>移入案卷号:</label>
                            <select id="newVolumeNumSeg" name="newVolumeNumSeg" onchange="newVolumeNumSegOnChange()"  style="width: 60%">
                            </select>
                        </div>
                    </div>
                </div>
                <div class="list-top" style="float:left;width:100%;" >
                    <div class="left-area" style="float:left;width:45%;">
                        <div class="top"style="height: 30px;width: 100%;">
                            <span style="font-size: 14px">原案卷文件列表：</span>
                            <table id="beforeVolumeTableSeg" class="beforeVolumeTableSeg">
                            </table>
                        </div>
                    </div>
                    <div class="mid-area" style="float:left;width: 10%;height:500px;text-align: center;">
                        <div style="margin-top: 200px;">
                            <div class="move-button-top"><button type="button" id="DeMoveTop" onclick="DeMoveLeftBtn()" class="btn blue" >左移</button></div><br><br>
                            <div  class="move-button"><button type="button" id="DeMoveBottom" onclick="DeMoveRightBtn()" class="btn blue">右移</button></div>
                        </div>

                    </div>
                    <div class="left-area" style="float:right;width:45%;">
                        <div class="top"style="height: 30px;width: 100%;">
                            <span style="font-size: 14px">文件列表：</span>
                            <table id="afterVolumeTableSeg" class="afterVolumeTableSeg">
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer" style="height:10%;">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" onclick="segmentSubmitAction()" class="btn btn-primary">转移提交</button>
            </div>
        </div>
    </div>
</div>


<!-- 合卷模态框（Modal） -->
<div class="modal fade" id="addAdjustVolModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="height: 730px;width: 1000px">
        <div class="modal-content" style="height: 100%;">
            <div class="modal-header" style="height: 5%;">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="addAdjustVolTitle">合卷调整</h4>
            </div>
            <div class="modal-body" style="height: 80%;">
                <%--<div style="height: 40px;width: 100%;float: left;">
                    <div class="top" style="height: 50px;float: left;">
                        <div class="form-inline" style="width: 400px">
                            <label>移入案卷号:</label>
                            <select id="addAdjustVolNum" name="addAdjustVolNum" style="width: 60%">
                            </select>
                        </div>
                    </div>
                </div>--%>
                <div class="list-top" style="float:left;width:100%;" >
                    <div class="left-area" style="float:left;width:100%;">
                        <div class="top"style="height: 45px;width: 100%;">
                            <span style="font-size: 14px">未组卷件列表：</span>
                            <table id="addAdjustItemTable" class="addAdjustItemTable">
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer" style="height:10%;">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" onclick="addAdjustSubmitAction()" class="btn btn-primary">合入提交</button>
            </div>
        </div>
    </div>
</div>


<!-- 拆卷模态框（Modal） -->
<div class="modal fade" id="unwindingVolModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="height: 800px;width: 1000px">
        <div class="modal-content" style="height: 100%;">
            <div class="modal-header" style="height: 5%;">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="unwindingVolTitle">拆卷调整</h4>
            </div>
            <div class="modal-body" style="height: 80%;">
                <div class="list-top" style="float:left;width:100%;" >
                    <div class="left-area" style="float:left;width:100%;">
                        <div class="top"style="height: 40px;width: 100%;">
                            <span style="font-size: 14px">卷内件列表：</span>
                            <table id="filesVolTable" class="filesVolTable">
                            </table>
                        </div>
                    </div>
                </div>

            </div>
            <div class="modal-footer" style="height:10%;">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" onclick="unwindingSubmitAction()" class="btn btn-primary">移出提交</button>
            </div>
        </div>
    </div>
</div>
<script>

    //------------------------------卷内顺序--调整---------------------------------
    //提交更改
    function orStartAdjust(){
        var nData = $('#orItemListTable').bootstrapTable('getData');
        var newData=JSON.stringify(nData);
        $.ajax({
            type: 'post',
            url: '${basePath}/pcwindow/archive/sort',
            data: {newData:newData},
            traditional: true,//这里设置为true
            success: function(result) {
                if (result.code == 1) {
                    var volIdSort = $("#volIdSort").val();
                    var opt = {
                        url: '${basePath}/pcwindow/archive/orAdjustOrder?volId='+volIdSort,
                        silent: true
                    };
                    $("#orItemListTable").bootstrapTable('refresh', opt);
                } else {
                    //alert("档案调整失败，请稍后再试");
                    confirmEvent("档案调整失败，请稍后再试");
                }
            }
        });
    }

    //分卷提交更改
    function segmentSubmitAction(){
        var volIdBeforeSeg=$("#volIdBeforeSeg").val();
        var volIdAfterSeg=$("#newVolumeNumSeg option:selected").val();
        //左边
        var beforeData1 = $('#beforeVolumeTableSeg').bootstrapTable('getData');
        //右边
        var afterData2 = $('#afterVolumeTableSeg').bootstrapTable('getData');
        var beforeData1=JSON.stringify(beforeData1);
        var afterData2=JSON.stringify(afterData2);
        $.ajax({
            type: 'post',
            url: '${basePath}/pcwindow/archive/deleteVolume',
            data: {beforeData1:beforeData1,afterData2:afterData2,volIdBeforeSeg:volIdBeforeSeg,volIdAfterSeg:volIdAfterSeg},
            traditional: true,//这里设置为true
            success: function(result) {
                if (result.code == 1) {
                    //刷新两张表
                    var opt = {
                        url: '${basePath}/pcwindow/archive/orAdjustOrder?volId='+volIdBeforeSeg,
                        silent: true,
                        cache:false
                    };
                    $("#beforeVolumeTableSeg").bootstrapTable('refresh', opt);
                    var opt = {
                        url: '${basePath}/pcwindow/archive/orAdjustOrder?volId='+volIdAfterSeg,
                        silent: true,
                        cache:false
                    };
                    $("#afterVolumeTableSeg").bootstrapTable('refresh', opt);

                } else {
                    confirmEvent("档案调整失败，请稍后再试");
                }
            }
        });
    }

    //合卷提交
    function addAdjustSubmitAction(){
        var rows = $("#addAdjustItemTable").bootstrapTable('getSelections');
        if(rows.length != 0){
            var idsItem = new Array();
            for (var i in rows) {
                idsItem.push(rows[i].itemId);
            }
            var volId = $("#volIdHE").val();
            $.ajax({
                type: "post",
                url: "${basePath}/pcwindow/sortOut/coVolume",
                data: { idsItem: idsItem.join("-"),volId:volId},
                success: function (data) {
                    if (data == "success") {
                        var opt = {
                            url: '${basePath}/pcwindow/archive/selectItemNot',
                            silent: true
                        };
                        $("#addAdjustItemTable").bootstrapTable('refresh', opt);
                        //$('#addAdjustVolModal').modal('hide');
                    }else {
                        confirmEvent(data);
                    }
                },
                error: function () {
                    confirmEvent('操作错误,请联系管理员!');
                }
            })
        }else{
            confirmEvent('请选择数据!');
        }
    }

    //拆卷提交
    function unwindingSubmitAction() {
        var rows = $("#filesVolTable").bootstrapTable('getSelections');
        if(rows.length != 0){
            var unItem = new Array();
            for (var i in rows) {
                unItem.push(rows[i].itemId);
            }
            var unVolId = $("#unwindingVolId").val();
            $.ajax({
                type: "post",
                url: "${basePath}/pcwindow/archive/moveOutItem",
                data: { unItems: unItem.join("-"),unVolId:unVolId},
                success: function (data) {
                    if (data == "success") {
                        var opt = {
                            url: '${basePath}/pcwindow/archive/selectVolItemAll?volId='+unVolId,
                            silent: true
                        };
                        $("#filesVolTable").bootstrapTable('refresh', opt);
                    }else {
                        confirmEvent(data);
                    }
                },
                error: function () {
                    confirmEvent('操作错误,请联系管理员!');
                }
            })
        }else{
            confirmEvent('请选择数据!');
        }
    }
    //获取model关闭事件
    $(function () {
        //分卷调整model关闭事件
        $('#segmentVolumeModal').on('hide.bs.modal', function () {
            //SearchNotArchive();暂定分卷完
            $("#newVolumeNumSeg").find("option").remove();
            $('#afterVolumeTableSeg').bootstrapTable('removeAll');
        });
    });
</script>